package loads

import (
	"jvm/nzpJvm/instructions/base"
	"jvm/nzpJvm/runtime_area"
)

// 将局部变量表指定位置的double类型变量压入操作数栈
type DLOAD struct{ base.Index8Instruction }
type DLOAD_0 struct{ base.NoOperandsInstruction }
type DLOAD_1 struct{ base.NoOperandsInstruction }
type DLOAD_2 struct{ base.NoOperandsInstruction }
type DLOAD_3 struct{ base.NoOperandsInstruction }

func (self *DLOAD) Execute(frame *runtime_area.Frame) {
	_dload(frame, self.Index)
}

func (self *DLOAD_0) Execute(frame *runtime_area.Frame) {
	_dload(frame, 0)
}

func (self *DLOAD_1) Execute(frame *runtime_area.Frame) {
	_dload(frame, 1)
}

func (self *DLOAD_2) Execute(frame *runtime_area.Frame) {
	_dload(frame, 2)
}

func (self *DLOAD_3) Execute(frame *runtime_area.Frame) {
	_dload(frame, 3)
}

func _dload(frame *runtime_area.Frame, index uint) {
	// 从栈帧的局部变量表中指定位置取出一个double值，
	val := frame.LocalVars().GetDouble(index)
	// 将其压到操作数栈中
	frame.OperandStack().PushDouble(val)
}
